<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>C语言程序设计-算术运算符 | hakutaku</title><meta name="author" content="hakutaku"><meta name="copyright" content="hakutaku"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="C语言程序设计—算术运算符一、复习旧知完成任务：编写程序，定义两个整型变量a，b，分别初始化为7，3；定义两个实型变量c，d,分别初始化为2.7，0.5，打印输出这些变量的值，输出格式如下： 12a &#x3D; 7,b &#x3D; 3c &#x3D; 2.700000,d &#x3D; 0.500000   参考答案：   int main() &amp;#123;     int a &#x3D; 7,b &#x3D; 3;     float c &#x3D; 2.">
<meta property="og:type" content="article">
<meta property="og:title" content="C语言程序设计-算术运算符">
<meta property="og:url" content="http://hakutakus.gitee.io/2023/10/27/c-operator/index.html">
<meta property="og:site_name" content="hakutaku">
<meta property="og:description" content="C语言程序设计—算术运算符一、复习旧知完成任务：编写程序，定义两个整型变量a，b，分别初始化为7，3；定义两个实型变量c，d,分别初始化为2.7，0.5，打印输出这些变量的值，输出格式如下： 12a &#x3D; 7,b &#x3D; 3c &#x3D; 2.700000,d &#x3D; 0.500000   参考答案：   int main() &amp;#123;     int a &#x3D; 7,b &#x3D; 3;     float c &#x3D; 2.">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://hakutakus.gitee.io/2023/10/27/c-operator/c.png">
<meta property="article:published_time" content="2023-10-27T02:43:28.000Z">
<meta property="article:modified_time" content="2023-10-27T07:50:14.057Z">
<meta property="article:author" content="hakutaku">
<meta property="article:tag" content="编程">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://hakutakus.gitee.io/2023/10/27/c-operator/c.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://hakutakus.gitee.io/2023/10/27/c-operator/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'C语言程序设计-算术运算符',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-10-27 15:50:14'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://5b0988e595225.cdn.sohucs.com/images/20180214/770692ef6e374d47b74109e98932e902.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">2</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 列表</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img fixed" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="hakutaku"><span class="site-name">hakutaku</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 列表</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">C语言程序设计-算术运算符</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-10-27T02:43:28.000Z" title="发表于 2023-10-27 10:43:28">2023-10-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-10-27T07:50:14.057Z" title="更新于 2023-10-27 15:50:14">2023-10-27</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="C语言程序设计-算术运算符"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><h3 id="C语言程序设计—算术运算符"><a href="#C语言程序设计—算术运算符" class="headerlink" title="C语言程序设计—算术运算符"></a>C语言程序设计—算术运算符</h3><h4 id="一、复习旧知"><a href="#一、复习旧知" class="headerlink" title="一、复习旧知"></a>一、复习旧知</h4><p>完成任务：编写程序，定义两个整型变量a，b，分别初始化为7，3；定义两个实型变量c，d,分别初始化为2.7，0.5，打印输出这些变量的值，输出格式如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">a = 7,b = 3</span><br><span class="line">c = 2.700000,d = 0.500000</span><br></pre></td></tr></table></figure>

<details>
<summary>参考答案：</summary>
<pre><code>  int main()
&#123;
    int a = 7,b = 3;
    float c = 2.7,d = 0.5;
    //占位符：%d->十进制整数，%f->保留六位小数的实数
    printf("a = %d,b = %d\n",a,b);
    printf("c = %f,d = %f\n",c,d);
    system("pause");
    return 0;
&#125;</code></pre>
</details>



<h4 id="二、导入新课"><a href="#二、导入新课" class="headerlink" title="二、导入新课"></a>二、导入新课</h4><details>
  <summary>1、在小学数学中，我们学习了那些运算？</summary>
  <p> 答：加（＋）、减（－）、乘（×）、除（÷）</p>
</details>


<details>
  <summary>2、在一个算式中存在以上多种运算时，我们按照什么顺序去算？</summary>
  <p>  答：先乘除，后加减。</p>
</details>


<details>
  <summary>3、有括号的？</summary>
  <p>  答：先算括号里面的。</p>
</details>

<p>4、接下来我们一起探究在C语言中如何进行算术运算。</p>
<h4 id="三、探究新知"><a href="#三、探究新知" class="headerlink" title="三、探究新知"></a>三、探究新知</h4><h5 id="1、C语言中的算术运算符"><a href="#1、C语言中的算术运算符" class="headerlink" title="1、C语言中的算术运算符"></a>1、C语言中的算术运算符</h5><table>
<thead>
<tr>
<th align="center">运算</th>
<th align="center">加</th>
<th align="center">减</th>
<th align="center">乘</th>
<th align="center">除</th>
<th align="center">求余</th>
</tr>
</thead>
<tbody><tr>
<td align="center">运算符</td>
<td align="center">+</td>
<td align="center">-</td>
<td align="center">*</td>
<td align="center">&#x2F;</td>
<td align="center">%</td>
</tr>
</tbody></table>
<h5 id="2、加法运算"><a href="#2、加法运算" class="headerlink" title="2、加法运算"></a>2、加法运算</h5><h6 id="2-1、演示代码："><a href="#2-1、演示代码：" class="headerlink" title="2.1、演示代码："></a>2.1、演示代码：</h6><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a = <span class="number">7</span>,b = <span class="number">3</span>;</span><br><span class="line">	<span class="type">float</span> c = <span class="number">2.7</span>,d = <span class="number">0.5</span>;</span><br><span class="line">	<span class="comment">//占位符：%d-&gt;十进制整数，%f-&gt;保留六位小数的实数</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d,b = %d\n&quot;</span>,a,b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c = %f,d = %f\n&quot;</span>,c,d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;加法（+）运算：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a + b = %d\n&quot;</span>,a + b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c + d = %f\n&quot;</span>,c + d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a + c = %f\n&quot;</span>,a + c);</span><br><span class="line">	system(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="2-2、运行结果："><a href="#2-2、运行结果：" class="headerlink" title="2.2、运行结果："></a>2.2、运行结果：</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">a = 7,b = 3</span><br><span class="line">c = 2.700000,d = 0.500000</span><br><span class="line">加法（+）运算：</span><br><span class="line">a + b = 10</span><br><span class="line">c + d = 3.200000</span><br><span class="line">a + c = 9.700000</span><br><span class="line">请按任意键继续. . .</span><br></pre></td></tr></table></figure>

<h5 id="3、减法和乘法"><a href="#3、减法和乘法" class="headerlink" title="3、减法和乘法"></a>3、减法和乘法</h5><h6 id="3-1、自主探究"><a href="#3-1、自主探究" class="headerlink" title="3.1、自主探究"></a>3.1、自主探究</h6><p>请同学们仿照上述代码进行减法和乘法运算！</p>
<h6 id="3-2、示例代码"><a href="#3-2、示例代码" class="headerlink" title="3.2、示例代码"></a>3.2、示例代码</h6><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a = <span class="number">7</span>,b = <span class="number">3</span>;</span><br><span class="line">	<span class="type">float</span> c = <span class="number">2.7</span>,d = <span class="number">0.5</span>;</span><br><span class="line">	<span class="comment">//占位符：%d-&gt;十进制整数，%f-&gt;保留六位小数的实数</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d,b = %d\n&quot;</span>,a,b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c = %f,d = %f\n&quot;</span>,c,d);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;加法（+）运算：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a + b = %d\n&quot;</span>,a + b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c + d = %f\n&quot;</span>,c + d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a + c = %f\n&quot;</span>,a + c);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;减法（-）运算：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a - b = %d\n&quot;</span>,a - b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c - d = %f\n&quot;</span>,c - d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a - c = %f\n&quot;</span>,a - c);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;乘法（*）运算：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a * b = %d\n&quot;</span>,a * b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c * d = %f\n&quot;</span>,c * d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a * c = %f\n&quot;</span>,a * c);</span><br><span class="line">	system(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="3-3、运行结果"><a href="#3-3、运行结果" class="headerlink" title="3.3、运行结果"></a>3.3、运行结果</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">a = 7,b = 3</span><br><span class="line">c = 2.700000,d = 0.500000</span><br><span class="line">加法（+）运算：</span><br><span class="line">a + b = 10</span><br><span class="line">c + d = 3.200000</span><br><span class="line">a + c = 9.700000</span><br><span class="line">减法（-）运算：</span><br><span class="line">a - b = 4</span><br><span class="line">c - d = 2.200000</span><br><span class="line">a - c = 4.300000</span><br><span class="line">乘法（*）运算：</span><br><span class="line">a * b = 21</span><br><span class="line">c * d = 1.350000</span><br><span class="line">a * c = 18.900000</span><br><span class="line">请按任意键继续. . .</span><br></pre></td></tr></table></figure>

<h6 id="3-4、小结"><a href="#3-4、小结" class="headerlink" title="3.4、小结"></a>3.4、小结</h6><p><strong>加（+），减（-），乘（*）运算，无实型参与运算时结果为整型，有实型参与运算时结果为实型。</strong></p>
<h5 id="4、除法运算"><a href="#4、除法运算" class="headerlink" title="4、除法运算"></a>4、除法运算</h5><h6 id="4-1、自主探究"><a href="#4-1、自主探究" class="headerlink" title="4.1、自主探究"></a>4.1、自主探究</h6><p>删除代码中加、减、乘法运算的代码，编写除法运算的代码，观察运行结果。</p>
<h6 id="4-2、示例代码"><a href="#4-2、示例代码" class="headerlink" title="4.2、示例代码"></a>4.2、示例代码</h6><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> a = <span class="number">7</span>,b = <span class="number">3</span>;</span><br><span class="line">	<span class="type">float</span> c = <span class="number">2.7</span>,d = <span class="number">0.5</span>;</span><br><span class="line">	<span class="comment">//占位符：%d-&gt;十进制整数，%f-&gt;保留六位小数的实数</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a = %d,b = %d\n&quot;</span>,a,b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c = %f,d = %f\n&quot;</span>,c,d);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;除法（/）运算：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a / b = %d\n&quot;</span>,a / b);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c / d = %f\n&quot;</span>,c / d);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;a / c = %f\n&quot;</span>,a / c);</span><br><span class="line"></span><br><span class="line">	system(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="4-3、运行结果"><a href="#4-3、运行结果" class="headerlink" title="4.3、运行结果"></a>4.3、运行结果</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">a = 7,b = 3</span><br><span class="line">c = 2.700000,d = 0.500000</span><br><span class="line">除法（/）运算：</span><br><span class="line">a / b = 2</span><br><span class="line">c / d = 5.400000</span><br><span class="line">a / c = 2.592593</span><br><span class="line">请按任意键继续. . .</span><br></pre></td></tr></table></figure>

<h6 id="4-4、疑问"><a href="#4-4、疑问" class="headerlink" title="4.4、疑问"></a>4.4、疑问</h6><details>
  <summary>1.为什么7除以3等于2？</summary>
  <p>  因为占位符是%d?改为%f会怎样？</p>
</details>

<h6 id="4-5、敲黑板"><a href="#4-5、敲黑板" class="headerlink" title="4.5、敲黑板"></a>4.5、敲黑板</h6><p>在C语言中两个整型数据做除法，结果仍为整型，不能整除时，小数部分将被直接出掉，<strong>不会四舍五入！不会四舍五入！！不会四舍五入！！！</strong></p>
<h5 id="5、取余运算"><a href="#5、取余运算" class="headerlink" title="5、取余运算"></a>5、取余运算</h5><h6 id="5-1、概念梳理"><a href="#5-1、概念梳理" class="headerlink" title="5.1、概念梳理"></a>5.1、概念梳理</h6><p>余数，数学用语。在整数的除法中，只有能整除与不能整除两种情况。当不能整除时，就产生余数，余数指整数除法中被除数未被除尽部分，且余数的取值范围为0到除数之间（不包括除数）的整数。</p>
<p><strong>例如：27除以6，商数为4，余数为3，即27÷6&#x3D;4……3，故27%6&#x3D;3。</strong></p>
<h6 id="5-2、敲黑板"><a href="#5-2、敲黑板" class="headerlink" title="5.2、敲黑板"></a>5.2、敲黑板</h6><p><strong>取余运算只能应用两个整数！</strong></p>
<h5 id="6、运算优先级"><a href="#6、运算优先级" class="headerlink" title="6、运算优先级"></a>6、运算优先级</h5><p><strong>与数学中无异，先乘除，后加减，有括号先算括号里面的。</strong></p>
<h4 id="四、练习巩固"><a href="#四、练习巩固" class="headerlink" title="四、练习巩固"></a>四、练习巩固</h4><h6 id="1、习题1"><a href="#1、习题1" class="headerlink" title="1、习题1"></a>1、习题1</h6><p>C语言程序中计算1&#x2F;2 + 1&#x2F;2 的结果为 1</p>
<p>​		A.正确        B.错误</p>
<h6 id="2、习题2"><a href="#2、习题2" class="headerlink" title="2、习题2"></a>2、习题2</h6><p>若有int a &#x3D; 17,b &#x3D; 5;float c &#x3D; 0.4;则：b * c,a &#x2F; b,a % b,c - b的结果分别为</p>
<p>​		A. 2 ,  3  ， 2 ， -4</p>
<p>​		B. 2 ,  3  ， 2 ， -4.6</p>
<p>​		C. 2.000000，3 , 2 ，-4.600000</p>
<p>​		D. 2.000000，2 , 3 ，-4.600000</p>
<h4 id="五、课堂小结"><a href="#五、课堂小结" class="headerlink" title="五、课堂小结"></a>五、课堂小结</h4><ol>
<li><p>C语言中的算术运算符：+ - * &#x2F; %。</p>
</li>
<li><p>加（+），减（-），乘（*）运算，无实型参与运算时结果为整型，有实型参与运算时结果为实型。</p>
</li>
<li><p>在C语言中两个整型数据做除法，结果仍为整型，不能整除时，小数部分将被直接去掉。</p>
</li>
<li><p>取余运算只能应用两个整数，余数指整数除法中被除数未被除尽的部分。</p>
</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="http://hakutakus.gitee.io">hakutaku</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="http://hakutakus.gitee.io/2023/10/27/c-operator/">http://hakutakus.gitee.io/2023/10/27/c-operator/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://hakutakus.gitee.io" target="_blank">hakutaku</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%BC%96%E7%A8%8B/">编程</a></div><div class="post_share"><div class="social-share" data-image="/2023/10/27/c-operator/c.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/2023/10/21/tvbox20231025/" title="TVBox，免费追剧，电视，手机，平板，电视盒子多端可用"><img class="cover" src="/2023/10/21/tvbox20231025/7.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">TVBox，免费追剧，电视，手机，平板，电视盒子多端可用</div></div></a></div></nav><hr class="custom-hr"/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎访问本站!</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#C%E8%AF%AD%E8%A8%80%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E2%80%94%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.</span> <span class="toc-text">C语言程序设计—算术运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%A4%8D%E4%B9%A0%E6%97%A7%E7%9F%A5"><span class="toc-number">1.1.</span> <span class="toc-text">一、复习旧知</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%AF%BC%E5%85%A5%E6%96%B0%E8%AF%BE"><span class="toc-number">1.2.</span> <span class="toc-text">二、导入新课</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%8E%A2%E7%A9%B6%E6%96%B0%E7%9F%A5"><span class="toc-number">1.3.</span> <span class="toc-text">三、探究新知</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81C%E8%AF%AD%E8%A8%80%E4%B8%AD%E7%9A%84%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.3.1.</span> <span class="toc-text">1、C语言中的算术运算符</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81%E5%8A%A0%E6%B3%95%E8%BF%90%E7%AE%97"><span class="toc-number">1.3.2.</span> <span class="toc-text">2、加法运算</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#2-1%E3%80%81%E6%BC%94%E7%A4%BA%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="toc-number">1.3.2.1.</span> <span class="toc-text">2.1、演示代码：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2-2%E3%80%81%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C%EF%BC%9A"><span class="toc-number">1.3.2.2.</span> <span class="toc-text">2.2、运行结果：</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3%E3%80%81%E5%87%8F%E6%B3%95%E5%92%8C%E4%B9%98%E6%B3%95"><span class="toc-number">1.3.3.</span> <span class="toc-text">3、减法和乘法</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#3-1%E3%80%81%E8%87%AA%E4%B8%BB%E6%8E%A2%E7%A9%B6"><span class="toc-number">1.3.3.1.</span> <span class="toc-text">3.1、自主探究</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-2%E3%80%81%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81"><span class="toc-number">1.3.3.2.</span> <span class="toc-text">3.2、示例代码</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-3%E3%80%81%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">1.3.3.3.</span> <span class="toc-text">3.3、运行结果</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-4%E3%80%81%E5%B0%8F%E7%BB%93"><span class="toc-number">1.3.3.4.</span> <span class="toc-text">3.4、小结</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4%E3%80%81%E9%99%A4%E6%B3%95%E8%BF%90%E7%AE%97"><span class="toc-number">1.3.4.</span> <span class="toc-text">4、除法运算</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#4-1%E3%80%81%E8%87%AA%E4%B8%BB%E6%8E%A2%E7%A9%B6"><span class="toc-number">1.3.4.1.</span> <span class="toc-text">4.1、自主探究</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#4-2%E3%80%81%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81"><span class="toc-number">1.3.4.2.</span> <span class="toc-text">4.2、示例代码</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#4-3%E3%80%81%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">1.3.4.3.</span> <span class="toc-text">4.3、运行结果</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#4-4%E3%80%81%E7%96%91%E9%97%AE"><span class="toc-number">1.3.4.4.</span> <span class="toc-text">4.4、疑问</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#4-5%E3%80%81%E6%95%B2%E9%BB%91%E6%9D%BF"><span class="toc-number">1.3.4.5.</span> <span class="toc-text">4.5、敲黑板</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5%E3%80%81%E5%8F%96%E4%BD%99%E8%BF%90%E7%AE%97"><span class="toc-number">1.3.5.</span> <span class="toc-text">5、取余运算</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#5-1%E3%80%81%E6%A6%82%E5%BF%B5%E6%A2%B3%E7%90%86"><span class="toc-number">1.3.5.1.</span> <span class="toc-text">5.1、概念梳理</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#5-2%E3%80%81%E6%95%B2%E9%BB%91%E6%9D%BF"><span class="toc-number">1.3.5.2.</span> <span class="toc-text">5.2、敲黑板</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#6%E3%80%81%E8%BF%90%E7%AE%97%E4%BC%98%E5%85%88%E7%BA%A7"><span class="toc-number">1.3.6.</span> <span class="toc-text">6、运算优先级</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%BB%83%E4%B9%A0%E5%B7%A9%E5%9B%BA"><span class="toc-number">1.4.</span> <span class="toc-text">四、练习巩固</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1%E3%80%81%E4%B9%A0%E9%A2%981"><span class="toc-number">1.4.0.1.</span> <span class="toc-text">1、习题1</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2%E3%80%81%E4%B9%A0%E9%A2%982"><span class="toc-number">1.4.0.2.</span> <span class="toc-text">2、习题2</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E8%AF%BE%E5%A0%82%E5%B0%8F%E7%BB%93"><span class="toc-number">1.5.</span> <span class="toc-text">五、课堂小结</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/10/27/c-operator/" title="C语言程序设计-算术运算符"><img src="/2023/10/27/c-operator/c.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C语言程序设计-算术运算符"/></a><div class="content"><a class="title" href="/2023/10/27/c-operator/" title="C语言程序设计-算术运算符">C语言程序设计-算术运算符</a><time datetime="2023-10-27T02:43:28.000Z" title="发表于 2023-10-27 10:43:28">2023-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/10/21/tvbox20231025/" title="TVBox，免费追剧，电视，手机，平板，电视盒子多端可用"><img src="/2023/10/21/tvbox20231025/7.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="TVBox，免费追剧，电视，手机，平板，电视盒子多端可用"/></a><div class="content"><a class="title" href="/2023/10/21/tvbox20231025/" title="TVBox，免费追剧，电视，手机，平板，电视盒子多端可用">TVBox，免费追剧，电视，手机，平板，电视盒子多端可用</a><time datetime="2023-10-21T12:00:17.000Z" title="发表于 2023-10-21 20:00:17">2023-10-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By hakutaku</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"><script>(() => {
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: '',
      region: '',
      onCommentLoaded: () => {
        btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
      }
    }, null))
  }

  const loadTwikoo = () => {
    if (typeof twikoo === 'object') setTimeout(init,0)
    else getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(init)
  }

  const getCount = () => {
    const countELement = document.getElementById('twikoo-count')
    if(!countELement) return
    twikoo.getCommentsCount({
      envId: '',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(res => {
      countELement.textContent = res[0].count
    }).catch(err => {
      console.error(err)
    })
  }

  if ('Twikoo' === 'Twikoo' || !true) {
    if (true) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else {
      loadTwikoo()
      GLOBAL_CONFIG_SITE.isPost && getCount()
    }
  } else {
    window.loadOtherComment = loadTwikoo
  }
})()</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>